#define  _CRT_SECURE_NO_WARNINGS 1
#include <iostream>
using namespace std;
#include <vector>

struct TreeNode
{
	int val;
	TreeNode* left;
	TreeNode* right;
	TreeNode(int x = 0)
		:val(x)
		,left(nullptr)
		,right(nullptr)
	{}
};

TreeNode* createTree(vector<int>& postOrder, int& index, vector<int>& inOrder, int left, int right)
{
	if (left > right) return nullptr;
	int key = postOrder[index--];
	int pos = left;
	for (int i = left; i <= right; i++)
	{
		if (inOrder[i] == key)
		{
			pos = i;
			break;
		}
	}
	TreeNode* node = new TreeNode(key);
	node->right = createTree(postOrder, index, inOrder, pos + 1, right);
	node->left = createTree(postOrder, index, inOrder, left, pos - 1);
	return node;
}

void prevOrder(TreeNode* root)
{
	if (root == nullptr) return;

	cout << root->val << ' ';
	prevOrder(root->left);
	prevOrder(root->right);
}

int main()
{
	int n = 0;
	cin >> n;
	vector<int> postOrder, inOrder;
	for (int i = 0; i < n; i++)
	{
		int tmp = 0;
		cin >> tmp;
		postOrder.push_back(tmp);
	}
	for (int i = 0; i < n; i++)
	{
		int tmp = 0;
		cin >> tmp;
		inOrder.push_back(tmp);
	}
	int i = n - 1;
	TreeNode* node = createTree(postOrder, i, inOrder, 0, n - 1);
	prevOrder(node);
	return 0;
}